    #include <stdio.h>
    #include <unistd.h>
    #include <sys/socket.h>
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/rfcomm.h>
#define PIPE_NAME "/tmp/car"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

    int main(int argc, char **argv)
    {
        struct sockaddr_rc addr = { 0 };
        int s, status, len=0;
        char dest[18] = "98:D3:31:B0:E8:F9";
        //char dest[18] = "";
        char buf[256];
        // allocate a socket
        s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

        // set the connection parameters (who to connect to)
        addr.rc_family = AF_BLUETOOTH;
        addr.rc_channel = (uint8_t) 1;
        str2ba( dest, &addr.rc_bdaddr );

        // connect to server
        status = connect(s, (struct sockaddr *)&addr, sizeof(addr));

		printf("connected\n");
		int res;
		if (access(PIPE_NAME, F_OK) == -1)
		{
			res = mkfifo(PIPE_NAME, 0777);
			if (res)
			{
				printf("error!");
				return 0;
			}
		}

		char buffer[1024];
		int pipe_fd = open(PIPE_NAME, O_RDONLY);
		if (pipe_fd != -1)
		{
			do
			{
				int len = read(pipe_fd, buffer, 1024);
				if (len > 0)
				{
					printf("len = %d %s\n",len, buffer);
					int s_len = write(s, buffer, strlen(buffer));
					printf("send len :%d\n", s_len);
				}
			}while(1);
		}


        if(status){
            printf(" failed to connect the device!\n");
            return -1;
        }
        do{
            len = read(s, buf, sizeof buf);
        
         if( len>0 ) {
             buf[len]=0;
             printf("%s\n",buf);
             write(s, buf, strlen(buf));
         }
        }while(len>0);

        close(s);
        return 0;
    }
